#include <pcap.h>
#include "utilities/utilities.h"
#include "PacketFileLoader.h"
#include "Capturer/FrameCapturer.h"

using boost::shared_ptr;
boost::shared_ptr<FrameCapturer> PacketFileLoader::loadFile(const QString& fpath)
{
	pcap_t* fp;
	char errbuf[PCAP_ERRBUF_SIZE];
	char filedesc[PCAP_BUF_SIZE];
	pcap_pkthdr* pkthdr;
	const unsigned char* pktdata;

	if (0 != pcap_createsrcstr(filedesc,PCAP_SRC_FILE,NULL,NULL,qPrintable(fpath),errbuf))
	{
		return shared_ptr<FrameCapturer>();
	}

	if (NULL == (fp = pcap_open(filedesc,65536,PCAP_OPENFLAG_PROMISCUOUS,1000,NULL,errbuf))) {
		return shared_ptr<FrameCapturer>();
	}

	return shared_ptr<FrameCapturer>(new FrameCapturer(fp));

}
